package com.punai.datapush.controller;

import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.datapush.domain.vo.ReleaseCaseVo;
import com.punai.datapush.service.IDataReleaseCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/datapush/releasecase")
public class ReleaseCaseController extends BaseController {

    @Autowired
    private IDataReleaseCaseService  releaseCaseService;

    @PreAuthorize("@ss.hasPermi('datapush:releasecase:list')")
    @GetMapping("list")
    public TableDataInfo list(ReleaseCaseVo vo) {
        startPage();
        return getDataTable(releaseCaseService.selectList(vo));
    }

    @PreAuthorize("@ss.hasPermi('datapush:releasecase:edit')")
    @PostMapping
    public AjaxResult add(@RequestBody ReleaseCaseVo vo) {
        if (releaseCaseService.checkDuplicationName(vo)) {
            AjaxResult.error("存在相同的发布名称");
        }
        return AjaxResult.success(releaseCaseService.add(vo));
    }

    @PreAuthorize("@ss.hasPermi('datapush:releasecase:edit')")
    @PutMapping
    public AjaxResult update(@RequestBody ReleaseCaseVo vo) {
        if (releaseCaseService.checkDuplicationName(vo)) {
            AjaxResult.error("存在相同的发布名称");
        }
        return AjaxResult.success(releaseCaseService.edit(vo));
    }

    @PreAuthorize("@ss.hasPermi('datapush:releasecase:remove')")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable String id) {
        return AjaxResult.success(releaseCaseService.removeById(id));
    }

    @PreAuthorize("@ss.hasPermi('datapush:releasecase:edit')")
    @PostMapping("/release/{id}")
    public AjaxResult release(@PathVariable String id) {
        return AjaxResult.success(releaseCaseService.release(id));
    }
    @PreAuthorize("@ss.hasPermi('datapush:releasecase:edit')")
    @PostMapping("/repealRelease/{id}")
    public AjaxResult repealRelease(@PathVariable String id) {
        return AjaxResult.success(releaseCaseService.repealRelease(id));
    }

    @GetMapping("{id}")
    public AjaxResult showResult(@PathVariable String id) {
        return AjaxResult.success(releaseCaseService.getById(id));
    }
    @PreAuthorize("@ss.hasPermi('datapush:releasecase:edit')")
    @PostMapping("/saveCaseSelect/{id}/{caseIds}")
    public AjaxResult saveCaseSelect(@PathVariable String id, @PathVariable String caseIds) {
        return AjaxResult.success(releaseCaseService.saveCaseSelect(id,caseIds));
    }
    @PreAuthorize("@ss.hasPermi('datapush:releasecase:edit')")
    @PostMapping("/saveCaseSelectRelease/{id}/{caseIds}")
    public AjaxResult saveCaseSelectRelease(@PathVariable String id, @PathVariable String caseIds) {
        return AjaxResult.success(releaseCaseService.saveCaseSelectRelease(id,caseIds));
    }

    @GetMapping("/checkShow/{id}")
    public AjaxResult checkShow(@PathVariable String id) {
        return AjaxResult.success(releaseCaseService.checkShow(id));
    }
}
